package com.trainoo.novel.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2018/8/19.
 */
public class SessionUtil {

    private static Logger logger = LoggerFactory.getLogger(SessionUtil.class);

    public static HttpSession getSession(){
        HttpSession session = null;
        try {
            RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
            HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
            session = request.getSession();
        }catch (Exception e){
            logger.error("获取session出现异常。", e);
        }
        return session;
    }
}
